package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocHouseprovidentDao;
import com.irdstudio.cdp.pboc.service.domain.PbocHouseprovident;
import com.irdstudio.cdp.pboc.service.facade.PbocHouseprovidentService;
import com.irdstudio.cdp.pboc.service.vo.PbocHouseprovidentVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 住房公积金参缴记录				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocHouseprovidentService")
public class PbocHouseprovidentServiceImpl implements PbocHouseprovidentService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocHouseprovidentServiceImpl.class);

	@Autowired
	private PbocHouseprovidentDao pbocHouseprovidentDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocHouseprovident(PbocHouseprovidentVO inPbocHouseprovidentVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocHouseprovidentVo.toString());
		int num = 0;
		try {
			PbocHouseprovident pbocHouseprovident = new PbocHouseprovident();
			beanCopy(inPbocHouseprovidentVo, pbocHouseprovident);
			num = pbocHouseprovidentDao.insertPbocHouseprovident(pbocHouseprovident);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocHouseprovidentVO inPbocHouseprovidentVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocHouseprovidentVo);
		int num = 0;
		try {
			PbocHouseprovident pbocHouseprovident = new PbocHouseprovident();
			beanCopy(inPbocHouseprovidentVo, pbocHouseprovident);
			num = pbocHouseprovidentDao.deleteByPk(pbocHouseprovident);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocHouseprovidentVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocHouseprovidentVO inPbocHouseprovidentVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocHouseprovidentVo.toString());
		int num = 0;
		try {
			PbocHouseprovident pbocHouseprovident = new PbocHouseprovident();
			beanCopy(inPbocHouseprovidentVo, pbocHouseprovident);
			num = pbocHouseprovidentDao.updateByPk(pbocHouseprovident);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocHouseprovidentVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocHouseprovidentVO queryByPk(PbocHouseprovidentVO inPbocHouseprovidentVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocHouseprovidentVo);
		try {
			PbocHouseprovident queryPbocHouseprovident = new PbocHouseprovident();
			beanCopy(inPbocHouseprovidentVo, queryPbocHouseprovident);
			PbocHouseprovident queryRslPbocHouseprovident = pbocHouseprovidentDao.queryByPk(queryPbocHouseprovident);
			if (Objects.nonNull(queryRslPbocHouseprovident)) {
				PbocHouseprovidentVO outPbocHouseprovidentVo = beanCopy(queryRslPbocHouseprovident, new PbocHouseprovidentVO());
				logger.debug("当前查询结果为:"+ outPbocHouseprovidentVo.toString());
				return outPbocHouseprovidentVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocHouseprovidentVO> queryAllOwner(PbocHouseprovidentVO pbocHouseprovidentVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocHouseprovidentVO> list = null;
		try {
			List<PbocHouseprovident> pbocHouseprovidents = pbocHouseprovidentDao.queryAllOwnerByPage(pbocHouseprovidentVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocHouseprovidents.size());
			pageSet(pbocHouseprovidents, pbocHouseprovidentVo);
			list = (List<PbocHouseprovidentVO>) beansCopy(pbocHouseprovidents, PbocHouseprovidentVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocHouseprovidentVO> queryAllCurrOrg(PbocHouseprovidentVO pbocHouseprovidentVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocHouseprovident> pbocHouseprovidents = pbocHouseprovidentDao.queryAllCurrOrgByPage(pbocHouseprovidentVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocHouseprovidents.size());
		List<PbocHouseprovidentVO> list = null;
		try {
			pageSet(pbocHouseprovidents, pbocHouseprovidentVo);
			list = (List<PbocHouseprovidentVO>) beansCopy(pbocHouseprovidents, PbocHouseprovidentVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocHouseprovidentVO> queryAllCurrDownOrg(PbocHouseprovidentVO pbocHouseprovidentVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocHouseprovident> pbocHouseprovidents = pbocHouseprovidentDao.queryAllCurrDownOrgByPage(pbocHouseprovidentVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocHouseprovidents.size());
		List<PbocHouseprovidentVO> list = null;
		try {
			pageSet(pbocHouseprovidents, pbocHouseprovidentVo);
			list = (List<PbocHouseprovidentVO>) beansCopy(pbocHouseprovidents, PbocHouseprovidentVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
